<?php

class Exts_Views_Helpers_Message extends Zend_View_Helper_FormElement {

	private $_types = array(
		Exts_Controller_Action_Helper_Message::ERROR,
		Exts_Controller_Action_Helper_Message::WARNING,
		Exts_Controller_Action_Helper_Message::NOTICE,
		Exts_Controller_Action_Helper_Message::SUCCESS
	);

	public function message() {
		$flashMessenger = Zend_Controller_Action_HelperBroker::getStaticHelper('Message');
		$html = '';
		foreach ($this->_types as $type) {
			$messages = $flashMessenger->getMessages($type);
			if (!$messages) {
				$messages = $flashMessenger->getCurrentMessages($type);
			}
			if ($messages) {
				if (!$html) {
					$html .= '<ul class="messages">';
				}
				$html .= '<li class="' . $type . '-msg">';
				$html .= '<ul>';
				foreach ($messages as $message) {
					$html .= '<li>';
					$html .= $message->message;
					$html .= '</li>';
				}
				$html .= '</ul>';
				$html .= '</li>';
			}
		}
		if (!empty($html)) {
			$html .= '</ul>';
		}
		return $html;
	}

}